//
//  main.c
//  C_8高级函数
//
//  Created by Robin on 16/3/18.
//  Copyright © 2016年 cnbm. All rights reserved.
//

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef enum {
    DUMP,
    SECOND_CHANCE,
    MARRIAGE
}responseType;

typedef struct {
    char *name;
    responseType type;
}response;

void dump (response *r);
void second_time (response *r);
void marriage (response *r);

int main(int argc, const char * argv[]) {
    
    response all[] = {{"Mike",DUMP},{"Matt",SECOND_CHANCE},{"Jack",SECOND_CHANCE},{"Tom",MARRIAGE}};
    
    // 创建函数指针数组
    void (*replies[])(response *r) = {dump,second_time,marriage};
    
    
//    for (int i=0; i<4; i++) {
//        response *r = &all[i];
//        switch (r->type) {
//            case DUMP:
//                dump(r);
//                break;
//            case SECOND_CHANCE:
//                second_time(r);
//                break;
//            case MARRIAGE:
//                marriage(r);
//                break;
//                
//            default:
//                break;
//        }
//    }
    
    for (int i=0; i<4; i++) {
        (*replies[(all[i].type)])(&(all[i]));
    }
    
    return 0;
}

void dump (response *r){
    printf("Dear %s\n",r->name);
    puts("Unfortunately your last date contacted us to");
    puts("say that they will not be seeing you again\n");
}

void second_time (response *r){
    
    printf("Dear %s\n",r->name);
    puts("Good news: your last date has asked us to");
    puts(" arrange another meeting Again\n");
}

void marriage (response *r){
    printf("Dear %s\n",r->name);
    puts("Let's marriaged");
}

